﻿using System;
using System.Xml.Serialization;

namespace HamcoWcs.Models.MesMessages
{
    [XmlRoot("MESSAGE")]
    public class MesMessage
    {

        public MesMessage()
        {
            Return = new MesMessageReturn(0, "");
        }

        public MesMessage(string messageName, string replySubjectName = "", string inboxName = "", string listener = "", BaseMesBody body = null) : this()
        {
            Header = new MesMessageHeader(messageName, replySubjectName, inboxName, listener);
            this.Body = body;
        }

        [XmlElement("HEADER")]
        public MesMessageHeader Header { get; set; }
        [XmlElement("BODY")]
        public BaseMesBody Body { get; set; }
        [XmlElement("RETURN")]
        public MesMessageReturn Return { get; set; }
    }


    /// <summary>MES消息头</summary>
    public class MesMessageHeader
    {

        public MesMessageHeader()
        {

        }
        public MesMessageHeader(string messageName, string replySubjectName = "CSOT.T7.MES.T7_DEV.FAB.AGVsvr", string inboxName = "", string listener = "")
        {
            this.MessageName = messageName;
            this.Time = DateTime.Now.ToString("yyyyMMddHHmmssffffff");
            this.Subject = replySubjectName;
            this.InboxName = inboxName;
            this.Listener = listener;
        }
        [XmlElement("MESSAGENAME")]
        public string MessageName { get; set; }
        [XmlElement("TRANSACTIONID")]
        public string Time { get; set; }

        // 2023/3/9 mes测试用subject CSOT.T7.MES.T7_DEV.FAB.AGVsvr
        [XmlElement("REPLYSUBJECTNAME")]
        public string Subject { get; set; } = "CSOT.T7.MES.T7_DEV.FAB.AGVsvr";
        [XmlElement("INBOXNAME")]
        public string? InboxName { get; set; }
        [XmlElement("LISTENER")]
        public string? Listener { get; set; }
    }

    /// <summary>MES消息return</summary>
    public class MesMessageReturn
    {
        public MesMessageReturn()
        {

        }
        public MesMessageReturn(int code, dynamic Message)
        {
            this.Code = code;
            this.Message = Message;
        }
        [XmlElement("RETURNCODE")]
        public int Code { get; set; }
        [XmlElement("RETURNMESSAGE")]
        public string Message { get; set; }
    }
}
